<template>
	<view class="content">
		<uni-search-bar @confirm="searchCityBus" v-model="searchKey"  />
		<swiper style="height: 200px;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-color="#ffd700" >
			<swiper-item v-for="(item,index) in lunboList">
			<view class="swiper-item">
			<image :src="item.img" mode="" style="width: 100%;"></image>
			</view>
		</swiper-item>
	</swiper>
	</view>
	<view   class="weather" style="height: 100rpx;border: 1px solid #ccc;margin: 8px; border-radius: 8px;display: flex;justify-content: space-between; padding: 4rpx;align-items: center;
				">
				<view class="icon" style="width: 100rpx;height: 100rpx;margin-right:5px ; ">
					<image style="width: 100%;height: 100%;" :src="'/static/icons/'+ weatherNow.icon +'.svg'"
						mode=""></image>
				</view>
				<view class="text" style="font-size: 50rpx;margin-right:200px;">
					{{weatherNow.temp}}°C
				</view>
				<view class="text" style="font-size: 34rpx;margin-left: -300rpx;">
					{{weatherNow.text}}
				</view>
				<view class="text" style=" margin-left: 10rpx;">
					{{weatherNow.windDir}} {{weatherNow.windScale}}级
				</view>
				<view>
					<view class="text" style="margin-left: 0rpx;">
						体感温度： {{weatherNow.feelsLike }}°C
					</view>
					<view class="text" style="margin-left: 0rpx;">
						湿度： {{weatherNow.humidity }}%
					</view>
				</view>
			</view>
	<uni-grid :show-border="false" :column="6" @change="changeGrid">
	  <uni-grid-item v-for="(item,index) in gridData" :index="index">
	    <view class="grid-item-box" style="background-color: #fff;">
	      <uni-icons :type="item.icon" :size="30" color="red" />
	        <text class="text1">{{item.title}}</text>
	    </view>
	  </uni-grid-item>
	
	</uni-grid>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		CONFIG
	} from '../../utils/config';
	
	onLoad(()=>{
		getLunbo()
		getWeather()
	})
	let lunboList=ref([])
	async function getLunbo() {
		let res = await uni.$get(CONFIG.leancloud_url + "/1.1/classes/Lunbo")
		console.log(res)
		lunboList.value = res.results
	}
	 let searchKey=ref("")
	 function searchCityBus(){
		 if(searchKey.value=="")
		 {
			 uni.showToast({
				 title:"请输入搜索线路名称",
				 icon:"none"
			 })
		 }else{
			 let url=`https://uri.amap.com/line?name=${searchKey.value}&city=029&callnative=0`
			 window.location.href=url
		 }
	 }
	 let weatherNow = ref({})
	 async function getWeather() {
	   let res = await uni.$get(CONFIG.hefeng_now, {
	     key: CONFIG.hefeng_key,
	     location: CONFIG.hefeng_location
	   })
	   if (res.code == 200) {
	     weatherNow.value = res.now
	     console.log(res.now)
	   }
	 }
	 let gridData = [{
	 			title: '热映电影',
	 			icon: 'videocam'
	  
	 		},
	 		{
	 			title: '长安八景',
	 			icon: 'star-filled'
	 		},
	 		{
	 			title: '每日运势',
	 			icon: 'image'
	 		},
	 		{
	 			title: '天气预报',
	 			icon: 'image'
	 		},
	 		{
	 			title: '景点',
	 			icon: 'image'
	 		}

	 
	 	]
</script>

<style>
	.content{
		background-color: gold;
	}
/* 网格容器样式 */
.uni-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr); /* 创建6列 */
  gap: 10px; /* 设置网格项之间的间距 */
  padding: 10px; /* 容器内边距 */
}

/* 网格项样式 */
.grid-item-box {
 border: 2px solid yellow; /* 设置边框颜色 */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* 添加阴影效果 */
  border-radius: 8px; /* 圆角边框 */
  transition: transform 0.3s ease-in-out; /* 平滑变换效果 */
  cursor: pointer; /* 鼠标悬停时显示指针 */
}

.grid-item-box:hover {

  transform: translateY(-5px); /* 鼠标悬停时上移 */
}

/* 图标样式 */
.uni-icons {
  margin-bottom: 10px; /* 图标与文本之间的间距 */
}

/* 文本样式 */
.text1 {
  font-size: 14px; /* 文本大小 */
  color: #333; /* 文本颜色 */
  text-align: center; /* 文本居中 */
}
</style>